package com.example.demo3;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport. TransportAddress;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;

import java.net.InetAddress ;
import java.net.UnknownHostException ;

public class ESClient {
    private static TransportClient client=null ;
    public static  Client getClient () {
        try {
            client=new PreBuiltXPackTransportClient(Settings.builder().put ("xpack.security.user","cy:123456").build()).addTransportAddress (new TransportAddress(InetAddress . getByName ("localhost"),9300));
        } catch (UnknownHostException e) {
            e.printStackTrace ();
        }
        return client ;
    }
}